package cn.deali.homework9;

import android.app.Application;

import java.util.ArrayList;

import cn.deali.homework9.model.Music;

public class MainApp extends Application {
    private static MainApp mApp;

    public static MainApp getInstance() {
        return mApp;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApp = this;
        playlist = new ArrayList<>();
    }

    // 当前播放
    private Music currentMusic;

    // 当前播放列表名称
    private String currentListName = "none";

    ArrayList<Music> playlist;

    /**
     * 下一首
     *
     * @return 是否有下一首
     */
    public boolean next() {
        if (currentMusic.getId() < playlist.size() - 1) {
            currentMusic = playlist.get(currentMusic.getId() + 1);
            return true;
        }
        return false;
    }

    /**
     * 上一首
     *
     * @return 是否有上一首
     */
    public boolean previous() {
        if (currentMusic.getId() > 0) {
            currentMusic = playlist.get(currentMusic.getId() - 1);
            return true;
        }
        return false;
    }

    public ArrayList<Music> getPlaylist() {
        return playlist;
    }

    public void setPlaylist(ArrayList<Music> playlist) {
        this.playlist = playlist;
    }

    public Music getCurrentMusic() {
        return currentMusic;
    }

    public void setCurrentMusic(Music currentMusic) {
        this.currentMusic = currentMusic;
    }

    public String getCurrentListName() {
        return currentListName;
    }

    public void setCurrentListName(String currentListName) {
        this.currentListName = currentListName;
    }
}
